package ch.exm.storm.query.join;

import java.util.ArrayList;
import java.util.Collection;

public class JoinedObject implements Cloneable {
	
	private Collection<Object> objects = new ArrayList<Object>();
	
	JoinedObject() { }
			
	JoinedObject(Object object) {
		add(object);
	}
	
	void add(Object object) {
		objects.add(object);
	}

	public Object getObjectByClass(Class<?> clazz) throws UnknownClassInJoinException {
		for (Object object : objects) if (clazz.isInstance(object)) return object;
		throw new UnknownClassInJoinException(this, clazz);
	}
	
	@Override
	public String toString() {
		return "Join of " + objects;
	}
	
	@Override
	protected Object clone() {
		JoinedObject clone = new JoinedObject();
		for (Object object : objects) clone.add(object);
		return clone;
	}
}
